package com.lcf.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by lancf on 2019/4/25.
 */
//@Component
//@Aspect
public class AopLog {


    //前置通知
    @Before("execution(* com.lcf.service.UserService.add00(..))")
    public void before(JoinPoint jp) {

        System.out.println("------->我是前置通知");
    }

    //后置通知
    @After("execution(* com.lcf.service.UserService.add0(..))")
    public void after(JoinPoint jp) {

        System.out.println("我是后置通知------->");
    }

    //运行通知
    @AfterReturning("execution(* com.lcf.service.UserService.add0(..))")
    public void afterReturning() {
        System.out.println("我是运行通知");
    }

    //异常通知
    @AfterThrowing("execution(* com.lcf.service.UserService.add0(..))")
    public void afterThrowing() {
        System.out.println("我是异常通知");
    }

    //环绕通知
    @Around("execution(* com.lcf.service.UserService.add0(..))")
    public void around(ProceedingJoinPoint proceed) throws Throwable {
        System.out.println("我是环绕通知之前置");

        proceed.proceed();//代理调用方法,如果代理的方法抛出异常,则不会执行后面代码
        System.out.println("我是环绕通知之后置");
    }

}
